package command

import (
	"fmt"
	"github.com/spf13/cobra"
	"strconv"
)

var (
	paramA string
	paramB string
)

// go run script/command.go testCmd --paramA 100 --paramB 200 hello go 2025
func init() {
	RootCmd.AddCommand(testCmd)
	testCmd.Flags().StringVarP(&paramA, "paramA", "o", "", "参数A")
	testCmd.MarkFlagRequired("paramA") //设置paramA必填
	testCmd.Flags().StringVarP(&paramB, "paramB", "d", "", "参数B")
}

var testCmd = &cobra.Command{
	Use:   "testCmd",
	Short: "关于testCmd的简短描述...",
	Long:  `关于testCmd的详细描述和用法,巴拉巴拉...`,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("--- test 运行 ---")
		fmt.Println("参数个数: " + strconv.Itoa(len(args)))
		testRun(args)
	},
}

func testRun(args []string) {

	fmt.Println(paramA)
	fmt.Println(paramB)

	for k, v := range args {
		fmt.Println(strconv.Itoa(k) + "=>" + v)
	}
}
